<template>
    <div class="baseTable" :style="{width: tableWidth, paddingBottom: paddingBottom}">
        <el-table :id="'baseTable-' + tableOptions.ref" class="table" v-loading="tableOptions.loading" :data="data"
                  :stripe="tableOptions.stripe" :size="tableOptions.size" :height="tableOptions.tableHeight"
                  :max-height="tableOptions.maxHeight" :ref="tableOptions.ref" :border="tableOptions.border"
                  :lazy="tableOptions.lazy" :tree-props="tableOptions.treeProps" :row-key="tableOptions.rowKey"
                  :cell-style="tableOptions.cellStyle" :default-expand-all="tableOptions.expandAllTree"
                  :expand-row-keys="tableOptions.expandRowKeys" :show-header="tableOptions.showHeader"
                  :key="tableOptions.key" :show-summary="tableOptions.showSummary"
                  :highlight-current-row="tableOptions.highlightCurrentRow"
                  :row-class-name="tableOptions.rowClassName" :summary-method="getSummaries"
                  :load="load" :span-method="spanMethod" @selection-change="handleSelectionChange"
                  @cell-click="handleCellClick" @cell-dblclick="handleCellDblClick"
                  @row-click="handleRowClick" @row-dblclick="handleRowDblClick"
                  @header-click="handleHeaderClick" @current-change="handleCurrentChange" :class="{'hide_select_all': hideSelectAll}">
            <div v-if="tableOptions.isExpand" style="overflow:hidden;">
                <el-table-column type="expand" width="1">
                    <template slot-scope="props">
                        <tableTemplate :data="props.row.childrenList"
                                       :options="tableOptions.itemTableOptions"></tableTemplate>
                    </template>
                </el-table-column>
            </div>
            <!--单选框-->
            <el-table-column width="45" align="center" v-if="tableOptions.radioSelect" prop="_radio" :fixed="tableOptions.selectFixed">
                <template slot-scope="scope">
                    <el-radio size="medium" class="radio_row" v-model="tableRadio" :label="scope.row"><i style="display: none;"/>
                    </el-radio>
                </template>
            </el-table-column>
            <!--多选框-->
            <el-table-column v-if="tableOptions.multiSelect" type="selection" width="40" prop="_section"
                             align="center" :selectable="tableOptions.isDisable" :fixed="tableOptions.selectFixed"/>
            <template v-if="!tableOptions.hideIndex">
                <el-table-column type="index" :width="tableOptions.indexWidth ? tableOptions.indexWidth : 60"
                                 align="center" label="序号" v-if="tableOptions.pagination" prop="_index" :fixed="tableOptions.indexFixed">
                    <template slot-scope="scope">
                        {{
                            tableOptions.pagination.pageSize * (tableOptions.pagination.pageIndex - 1) + scope.$index + 1
                        }}
                    </template>
                </el-table-column>
                <el-table-column type="index" :width="tableOptions.indexWidth ? tableOptions.indexWidth : 60"
                                 align="center" label="序号" v-if="!tableOptions.pagination" prop="_index" :fixed="tableOptions.indexFixed"/>
            </template>
            <!--数据列-->
            <template v-for="(item, index) in tableOptions.columns">
                <children-column v-if="item.children && item.children.length > 0" :key="index" :index="index"
                                 :col="item" :edit="tableOptions.edit"/>
                <table-column v-else :key="index" :index="index" :col="item" :edit="tableOptions.edit"/>
            </template>
            <!--按钮操作组-->
            <operate-column :operates="tableOptions.operates" />
        </el-table>
        <div style="height: 5px;" v-if="tableOptions.pagination"></div>
        <el-pagination v-if="tableOptions.pagination" @size-change="handleSizeChange"
                       @current-change="handleIndexChange"
                       :page-size="tableOptions.pagination.pageSize" :page-sizes="tableOptions.pagination.pageArray"
                       :current-page="tableOptions.pagination.pageIndex"
                       layout="total,sizes, prev, pager, next,jumper"
                       :total="tableOptions.pagination.total"></el-pagination>
    <tableExport ref="tableExport" :tableOptions="tableOptions" ></tableExport>
    </div>
</template>

<script>
import './BaseTable.css';
import TableSearch from "./TableSearch";
import TableColumn from "./TableColumn";
import ChildrenColumn from "./ChildrenColumn";
import tableExport from './export/export'
import OperateColumn from "./OperateColumn";

export default {
        name: 'BaseTable',
        props: {
            data: {
                type: Array,
                default () {
                    return [];
                }
            },
            options: {
                type: Object,
                default () {
                    return {};
                }
            }
        },
        components: {
            tableExport,
            TableColumn,
            ChildrenColumn,
            OperateColumn,
            expandDom: {
                functional: true,
                props: {
                    row: Object,
                    render: Function,
                    index: Number,
                    column: {
                        type: Object,
                        default: null,
                    }
                },
                render: (h, ctx) => {
                    const params = {
                        row: ctx.props.row,
                        index: ctx.props.index,
                    };
                    if (ctx.props.column) {
                        params.column = ctx.props.column;
                    }
                    return ctx.props.render(h, params);
                },
            },
            expandHeader: {
                functional: true,
                props: {
                    row: Object,
                    headerRender: Function,
                    index: Number,
                    column: {
                        type: Object,
                        default: null,
                    }
                },
                render: (h, ctx) => {
                    const params = {
                        row: ctx.props.row,
                        index: ctx.props.index,
                    };
                    if (ctx.props.column) {
                        params.column = ctx.props.column;
                    }
                    if (ctx.props.headerRender) {
                        return ctx.props.headerRender(h, params);
                    } else {
                        return h('span', ctx.props.column.label);
                    }
                },
            },
            popover: {
                functional: true,
                props: {
                    content: Function,
                    column: {
                        type: Object,
                        default: null,
                    }
                },
                render: (h, ctx) => {
                    return ctx.props.content(h, ctx.props.column);
                },
            }
        },
        data () {
            return {
                tableRadio: {},
                multipleSelection: [],
                tableOptions: {},
                tableSearchCache: [],
                defaultOptions: {
                    selectFixed:'left',
                    indexFixed:'left',
                    edit: true,
                    container: '',
                    subHeight: 0,
                    disabledClickSelect: false,
                    hideIndex: false,
                    showHeader: true,
                    showSummary: false,
                    summaryLabel: '合计',
                    ref: 'mutipleTable',
                    size: 'mini',
                    border: true,
                    lazy: false,
                    treeProps: {
                        children: 'children',
                        hasChildren: 'hasChildren'
                    },
                    expandAllTree: false,
                    rowKey: 'id',
                    loading: false,//是否添加表格loading加载动画
                    stripe: false, //是否为斑马纹 table
                    highlightCurrentRow: false, //是否要高亮当前行
                    //需要展示的列
                    //prop：列数据对应的属性，label：列名，align：对齐方式，width：列宽,
                    //resizable: 对应列是否可以通过拖动改变宽度（需要在 el-table 上设置 border 属性为真）
                    columns: [],
                    multiSelect: false,
                    radioSelect: false,
                    //操作按钮组
                    // label: 文本，
                    // type :类型（primary / success / warning / danger / info / text），
                    // show：是否显示，
                    // icon：按钮图标，
                    // plain：是否朴素按钮，
                    // disabled：是否禁用，
                    // method：回调方法，
                    // size: 大小
                    operates: {
                        fixed:'right',
                        list: []
                    },
                    pagination: false,
                    cellStyle ({row, column, rowIndex, columnIndex}) {
                    },
                    getMaxHeight () {
                        return undefined;
                    },
                    exportConfig:{
                        visible: false,
                        title: '导出参数配置',//导出弹框标题
                        showDialog:true,//是否显示导出弹框
                        url:"",//请求数据url
                        queryData:"",//请求数据搜索条件
                        filename:document.title,//导出默认文件名
                        convert:{//数据字典转换
                        },
                    },
                    printConfig:{
                        sheetName: document.title, //打印页眉名称
                    }
                },
                defaultTooltip: {
                    effect: 'dark', //默认提供的主题-dark/light
                    placement: 'top',//Tooltip 的出现位置-top/top-start/top-end/bottom/bottom-start/bottom-end/left/left-start/left-end/right/right-start/right-end
                    content: '',//显示的内容
                    disabled: false,//Tooltip 是否可用
                    offset: 0,//出现位置的偏移量
                    transition: 'el-fade-in-linear',//定义渐变动画
                    visibleArrow: true,//是否显示 Tooltip 箭头
                    popperOptions: {},//popper.js 的参数
                    openDelay: 0,//延迟出现，单位毫秒
                    manual: false,//手动控制模式，设置为 true 后，mouseenter 和 mouseleave 事件将不会生效
                    popperClass: '',//为 Tooltip 的 popper 添加类名
                    enterable: false,//鼠标是否可进入到 tooltip 中
                    hideAfter: 0,//Tooltip 出现后自动隐藏延时，单位毫秒，为 0 则不会自动隐藏
                },
                popoverOptions: {},
                filter: () => {
                    return true;
                },
            };
        },
        computed: {
            tableWidth () {
                if (this.tableOptions.width !== undefined) {
                    if (typeof this.tableOptions.width === 'number') {
                        return `${this.tableOptions.width}px`;
                    } else {
                        return this.tableOptions.width;
                    }
                }
                return '100%';
            },
            paddingBottom() {
                if (this.tableOptions.pagination) {
                    return '32px';
                }
                return undefined;
            },
            hideSelectAll() {
                if (typeof this.tableOptions.isDisable === 'function') {
                    let dataList = this.data || [];
                    let filter = dataList.filter(item => !this.tableOptions.isDisable(item));
                    return filter.length > 0;
                }
                return false;
            },
        },
        watch: {
            options: {
                handler () {
                    this.initTableOptions(this.options);
                },
                deep: true,
                immediate: true,
            },
        },
        created () {
            let _this = this;
            _this.initTableOptions(_this.options);
            window.onresize = () => {
                _this.resizeTable();
            };
        },
        activated () {
            this.resizeTable();
        },
        methods: {
            resizeTable () {
                let _this = this;
                this.$nextTick(() => {
                    let hasTabs = $('#app').find('.tabs_wrapper').length > 0;
                    if (hasTabs) {
                        this.resizeTabsTable();
                    } else {
                        let maxH = _this.tableOptions.getMaxHeight();
                        if (maxH) {
                            _this.tableOptions = $.extend({}, _this.tableOptions, {
                                maxHeight: maxH,
                            });
                        } else {
                            if (_this.$utils.isNotEmpty(_this.tableOptions.container)) {
                                let maxHeight = $('#app').find('.app_content').height();
                                let cardHeader = $(_this.tableOptions.container).find('.el-card__header');
                                if (cardHeader.length > 0) {
                                    let chHeight = cardHeader.outerHeight();
                                    if (chHeight < 52) {
                                        chHeight = 52;
                                    }
                                    maxHeight -= chHeight;
                                }
                                let buttons = $(_this.tableOptions.container).find('.buttons');
                                if (buttons.length > 0) {
                                    maxHeight -= buttons.outerHeight();
                                }
                                if (_this.tableOptions.pagination) {
                                    let pagination = $('.baseTable').find('.el-pagination');
                                    if (pagination.length > 0) {
                                        maxHeight -= (pagination.outerHeight() + 35);
                                    }
                                    maxHeight -= 12;
                                } else {
                                    maxHeight -= 24;
                                }
                                if (_this.tableOptions.subHeight) {
                                    maxHeight -= _this.tableOptions.subHeight;
                                }
                                if (maxHeight > 0) {
                                    if(maxHeight<300){
                                       maxHeight = 300
                                    }
                                    _this.tableOptions = $.extend({}, _this.tableOptions, {
                                        maxHeight: maxHeight,
                                    });
                                }
                            }
                        }
                        setTimeout(() => {
                            let container = $('#app');
                            if (_this.$utils.isNotEmpty(_this.tableOptions.container)) {
                                container = $('#app').find(_this.tableOptions.container);
                            }
                            let height = $(container).find('.box-card').find('.baseTable').find('.table').height();
                            let maxHeight = $(container).find('.box-card').find('.baseTable').find('.table').css('maxHeight');
                            let hasMaxHeight = maxHeight !== 'none';
                            let fixedLeft = $(container).find('.box-card').find('.baseTable .table').find('.el-table__fixed-left');
                            if (fixedLeft && fixedLeft.length > 0) {
                                if (hasMaxHeight) {
                                    fixedLeft.css('height', 'auto');
                                    fixedLeft.css('maxHeight', maxHeight);
                                } else {
                                    fixedLeft.height(height);
                                }
                            }
                            let fixedRight = $(container).find('.box-card').find('.baseTable .table').find('.el-table__fixed-right');
                            if (fixedRight && fixedRight.length > 0) {
                                if (hasMaxHeight) {
                                    fixedRight.css('height', 'auto');
                                    fixedRight.css('maxHeight', maxHeight);
                                } else {
                                    fixedRight.height(height);
                                }
                            }
                        }, 2);

                    }
                });
            },
            resizeTabsTable () {
                let _this = this;
                let maxH = _this.tableOptions.getMaxHeight();
                if (maxH) {
                    _this.tableOptions = $.extend({}, _this.tableOptions, {
                        maxHeight: maxH,
                    });
                } else {
                    let tabsWrapper = $('#app').find('.tabs_wrapper');
                    let activeTabs = $(tabsWrapper).find('.el-tabs__nav').find('.el-tabs__item.is-active');
                    let tabPane = $(activeTabs).attr('aria-controls');
                    let tabContainer = $(tabsWrapper).find(`#${tabPane}`);
                    if (_this.$utils.isNotEmpty(_this.tableOptions.container)) {
                        let maxHeight = $(tabContainer).find('.tab_content').height();

                        // let cardHeader = $(tabContainer).find(_this.tableOptions.container).find('.el-card__header');
                        let cardHeader = $(tabContainer).find('.el-card__header');
                        if (cardHeader.length > 0) {
                            let chHeight = cardHeader.outerHeight();
                            if (chHeight < 52) {
                                chHeight = 52;
                            }
                            maxHeight -= chHeight;
                        }
                        // let buttons = $(tabContainer).find(_this.tableOptions.container).find('.buttons');
                        let buttons = $(tabContainer).find('.el-card__body').find('.buttons');
                        if (buttons.length > 0) {
                            maxHeight -= buttons.outerHeight();
                        }
                        if (_this.tableOptions.pagination) {
                            // let pagination = $(tabContainer).find(_this.tableOptions.container).find('.baseTable').find('.el-pagination');
                            let pagination = $(tabContainer).find('.baseTable').find('.el-pagination');
                            if (pagination.length > 0) {
                                maxHeight -= (pagination.outerHeight() + 35);
                            }
                            // maxHeight -= 12;
                        } else {
                            maxHeight -= 24;
                        }
                        if (_this.tableOptions.subHeight) {
                            maxHeight -= _this.tableOptions.subHeight;
                        }

                        let contraction= $(tabContainer).find('.el-card__header').find('.my-contraction')
                        if(contraction&&contraction.length>0&&buttons.length==0){
                            let baseTable = $(tabContainer).find('.el-card__body').find('.baseTable')
                            baseTable.css('margin-top', '25px')
                            maxHeight -=25
                        }

                        if (maxHeight > 0) {
                            if(maxHeight<300){
                               maxHeight = 300
                            }
                            _this.tableOptions = $.extend({}, _this.tableOptions, {
                                maxHeight: maxHeight,
                            });
                        }
                    }
                    setTimeout(() => {
                        let height = $(tabContainer).find('.box-card').find('.baseTable').find('.table').height();
                        let maxHeight = $(tabContainer).find('.box-card').find('.baseTable').find('.table').css('maxHeight');
                        let hasMaxHeight = maxHeight !== 'none';
                        let fixedLeft = $(tabContainer).find('.box-card').find('.baseTable .table').find('.el-table__fixed-left');
                        if (fixedLeft && fixedLeft.length > 0) {
                            if (hasMaxHeight) {
                                fixedLeft.css('height', 'auto');
                                fixedLeft.css('maxHeight', maxHeight);
                            } else {
                                fixedLeft.height(height);
                            }
                        }
                        let fixedRight = $(tabContainer).find('.box-card').find('.baseTable .table').find('.el-table__fixed-right');
                        if (fixedRight && fixedRight.length > 0) {
                            if (hasMaxHeight) {
                                fixedRight.css('height', 'auto');
                                fixedRight.css('maxHeight', maxHeight);
                            } else {
                                fixedRight.height(height);
                            }
                        }
                    }, 2);
                }
            },
            initTableOptions (options) {
                if (options.multiSelect && this.$utils.isNotEmptyList(options.multipleSelection)) {
                    this.multipleSelection = [].concat(options.multipleSelection);
                } else {
                    this.multipleSelection = [];
                }
                if (options.radioSelect && options.tableRadio) {
                    this.tableRadio = options.tableRadio;
                } else {
                    this.tableRadio = undefined;
                }
                this.tableOptions = $.extend({}, this.defaultOptions, options);
                if (this.tableOptions.selectFixed === 'none') {
                    delete this.tableOptions.selectFixed;
                }
                if (this.tableOptions.indexFixed === 'none') {
                    delete this.tableOptions.indexFixed;
                }
                this.tableSearchCache = [];
                if (this.tableOptions.pagination) {
                    if (!this.tableOptions.pagination.pageSize) {
                        this.tableOptions.pagination.pageSize = window.configs.pageSize;
                    }
                    if (!this.tableOptions.pagination.pageArray) {
                        this.tableOptions.pagination.pageArray = window.configs.pageSizes;
                    }
                }
                if (this.tableOptions.operates.list && this.tableOptions.operates.list.length > 0) {
                    let witdh = 5
                    this.tableOptions.operates.list.forEach(item => {
                        witdh +=30
                        if (item.filter === undefined) {
                            item.filter = this.filter;
                        }
                    });
                    this.tableOptions.operates.width =this.tableOptions.operates.width?this.tableOptions.operates.width: witdh
                }
                this.tableOptions.columns.forEach(item => {

                    if (item.isCheck === undefined) {
                        item.isCheck = true
                    }
                    if (item.search) {
                        item.renderHeader = (h, data) => {
                            return this.renderColumnHeader(h, data, item);
                        };
                    }
                });

                this.tableOptions = $.extend({}, this.tableOptions, {
                    operates: $.extend({},this.defaultOptions.operates, this.tableOptions.operates, {
                        list: this.initTableOperates(this.tableOptions.operates.list),
                    }),
                    exportConfig: $.extend({},this.defaultOptions.exportConfig, this.tableOptions.exportConfig),
                    printConfig: $.extend({},this.defaultOptions.printConfig, this.tableOptions.printConfig),
                });

                this.$nextTick(() => {
                    this.resizeTable();
                });
            },
            initTableOperates (datas) {
                let list = [];
                if (datas && datas.length > 0) {
                    datas.forEach(item => {
                        let obj = $.extend({}, item);
                        if (item.tooltip && this.$utils.isNotEmpty(item.tooltip.content)) {
                            obj.tooltip = $.extend({}, this.defaultTooltip, item.tooltip);
                        }
                        list.push(obj);
                    });
                }
                return list;
            },
            getColumnDatas (columns) {
                let list = [];
                if (columns && columns.length > 0) {
                    columns.forEach(item => {
                        let object = $.extend({}, item);
                        list.push(object);
                        if (item.children && item.children.length > 0) {
                            let childs = this.getColumnDatas(item.children);
                            if (childs.length > 0) {
                                childs.forEach(child => {
                                    list.push(child);
                                });
                            }
                        }
                    });
                }
                return list;
            },
            getColumnOpt (property) {
                let columns = this.getColumnDatas(this.tableOptions.columns);
                let filter = columns.filter(item => item.prop === property);
                return filter && filter.length > 0 ? filter[0] : {};
            },
            checkField (item) {
                if (item.spanOption && this.$utils.isNotEmptyList(item.spanOption.hideField)) {
                    return item.spanOption.hideField.indexOf('_section') === -1;
                }
                return true;
            },
            handleSelectionChange (val) {
                this.multipleSelection = val.filter(item => this.checkField(item));
                this.$emit('handleSelectionChange', this.multipleSelection);
                this.$emit('event', {type: 'selectionChange', value: this.multipleSelection});
            },
            handleCurrentChange (item) {
                this.$emit('handleCurrentChange', item);
                this.$emit('event', {type: 'currentChange', value: item});
            },
            handleCellClick (row, column, event) {
                let ref = this.$refs[this.tableOptions.ref];
                let columnOpt = this.getColumnOpt(column.property);
                this.$emit('handleCellClick', {ref, row, column, event, columnOpt});
                this.$emit('event', {type: 'cellClick', ref, row, column, event, columnOpt});
            },
            handleCellDblClick (row, column, event) {
                let ref = this.$refs[this.tableOptions.ref];
                let columnOpt = this.getColumnOpt(column.property);
                this.$emit('handleCellDblClick', {ref, row, column, event, columnOpt});
                this.$emit('event', {type: 'cellDblClick', ref, row, column, event, columnOpt});
            },
            handleRowClick (row, column, event) {
                let ref = this.$refs[this.tableOptions.ref];
                //点击行选中
                let cleckSelectDisabled = true;
                if (typeof this.tableOptions.isDisable === 'function') {
                    cleckSelectDisabled = this.tableOptions.isDisable(row);
                }
                if (cleckSelectDisabled && !this.tableOptions.disabledClickSelect
                        && (this.tableOptions.multiSelect || this.tableOptions.radioSelect)
                        && column.property !== 'operates') {
                    if (this.checkField(row)) {
                        if (this.tableOptions.multiSelect) {
                            ref.toggleRowSelection(row);
                        }
                        if (this.tableOptions.radioSelect) {
                            this.tableRadio = row;
                        }
                    }
                } else {
                    if (column && column.property === '_radio') {
                        this.tableRadio = row;
                    }
                }
                if (column) {
                    let columnOpt = this.getColumnOpt(column.property);
                    this.$emit('handleRowClick', {ref, row, column, event, columnOpt});
                    this.$emit('event', {type: 'rowClick', ref, row, column, event, columnOpt});
                }
            },
            handleHeaderClick (column, event) {
                let ref = this.$refs[this.tableOptions.ref];
                this.$emit('handleHeaderClick', {ref, column, event});
                this.$emit('event', {type: 'headerClick', ref, column, event});
            },
            handleRowDblClick (row, column, event) {
                let ref = this.$refs[this.tableOptions.ref];
                let columnOpt = this.getColumnOpt(column.property);
                this.$emit('handleRowDblClick', {ref, row, column, event, columnOpt});
                this.$emit('event', {type: 'rowDblClick', ref, row, column, event, columnOpt});
            },
            load (tree, treeNode, resolve) {
                this.$emit('load', {tree: tree, treeNode: treeNode, resolve: resolve});
                this.$emit('event', {type: 'load', tree, treeNode, resolve});
            },
            //切换每页显示的数量
            handleSizeChange (size) {
                if (this.tableOptions.pagination) {
                    this.tableOptions.pagination.pageIndex = 1;
                    this.tableOptions.pagination.pageSize = size;
                    this.$emit('handleChangePage', {pageIndex: 1, pageSize: size});
                }
            },
            handleIndexChange (current) {
                this.tableOptions.pagination.pageIndex = current;
                this.$emit('handleChangePage', {pageIndex: current, pageSize: this.tableOptions.pagination.pageSize});
            },
            spanMethod ({row, column, rowIndex, columnIndex}) {
                if (this.tableOptions.spanMethod === undefined) {
                    if (row.spanOption) {
                        let option = row.spanOption[column.property];
                        let hideField = row.spanOption.hideField;
                        if (hideField && hideField.length > 0) {
                            if (hideField.indexOf(column.property) !== -1) {
                                return {
                                    rowspan: 0,
                                    colspan: 0
                                };
                            }
                        }
                        if (option) {
                            if (!option.rowspan) {
                                option.rowspan = 0;
                            }
                            if (!option.colspan) {
                                option.colspan = 0;
                            }
                            return option;
                        }
                    }
                } else {
                    this.tableOptions.spanMethod({row, column, rowIndex, columnIndex});
                }
            },
            getSummaries: function (param) {
                let $this = this;
                const {columns, data} = param;
                let sums = [];
                columns.forEach((column, index) => {
                    if (index === 0 && ['_section', '_radio'].indexOf(column.property) === -1) {
                        sums[index] = $this.tableOptions.summaryLabel;
                        return;
                    }
                    if (column.property === '_index') {
                        sums[index] = $this.tableOptions.summaryLabel;
                        return;
                    }
                    const values = data.map(item => Number(item[column.property]));
                    let isSummary = false;
                    if (this.tableOptions.summaryArray && this.tableOptions.summaryArray.length > 0) {
                        let arrIdx = this.tableOptions.summaryArray.findIndex(item => {
                            return item === column.property;
                        });
                        isSummary = arrIdx !== - 1;
                    } else {
                        isSummary = !values.every(value => isNaN(value));
                    }
                    if (isSummary) {
                        sums[index] = values.reduce((prev, curr) => {
                            const value = Number(curr);
                            if (!isNaN(value)) {
                                return $this.$utils.accAdd(Number(prev), Number(curr));
                            } else {
                                return prev;
                            }
                        }, 0);
                    } else {
                        sums[index] = "N/A";
                    }
                });
                sums = sums.map(item => {
                    item = item === "N/A" ? "" : item;
                    return item;
                });

                return sums;
            },
            renderColumnHeader (h, data, column) {
                let $this = this;
                return h(TableSearch, {
                    props: {
                        options: {
                            h, data, column,
                            label: column.label,
                            cache: $this.tableSearchCache,
                        },
                    },
                    on: {
                        searchOperate (data) {
                            let object = $.extend({}, data);
                            if (data.type && data.type === 'clear') {
                                $this.tableSearchCache = $this.tableSearchCache.filter(item => item.field !== data.field);
                            } else {
                                let filter = $this.tableSearchCache.filter(item => item.field === data.field);
                                if (filter.length > 0) {
                                    $this.tableSearchCache = $this.tableSearchCache.filter(item => item.field !== data.field);
                                }
                                delete object.type;
                                $this.tableSearchCache.push(object);
                            }
                            typeof column.search.method === 'function' && column.search.method($this.tableSearchCache);
                        },
                    },
                });
            },
            toggleRowSelection (row, selected) {
                if (this.$refs[this.tableOptions.ref]) {
                    if (this.tableOptions.multiSelect) {
                        this.$refs[this.tableOptions.ref].toggleRowSelection(row, selected);
                    }
                    if (this.tableOptions.radioSelect) {
                        this.tableRadio = row;
                    }
                }
            },
            clearSelection () {
                if (this.$refs[this.tableOptions.ref]) {
                    if (this.tableOptions.multiSelect) {
                        this.$refs[this.tableOptions.ref].clearSelection();
                    }
                    if (this.tableOptions.radioSelect) {
                        this.tableRadio = undefined;
                    }
                }
            },
            getSelection() {
                if (this.tableOptions.multiSelect) {
                    return this.multipleSelection;
                }
                if (this.tableOptions.radioSelect) {
                    return this.tableRadio;
                }
            },
            showEvent (evnt,options) {
                this.$refs.tableExport.showEvent(this,options)
            },
        },
    }
</script>
